package org.jeecg.common.util;


import cn.hutool.json.JSONUtil;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class AliyunSmsUtils {
    public static void sendSms(String mobile,String tempCode,Object param) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FmjinJVdYBiTqNhsXZd", "pRGUqC44n9PG9kGdbYNgP3xCu2p7RE");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request .setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId","cn-hangzhou");
        request.putQueryParameter("PhoneNumbers",mobile);
        request.putQueryParameter("SignName","大医智慧");
        request.putQueryParameter("TemplateCode",tempCode);
        request.putQueryParameter("TemplateParam", JSONUtil.toJsonStr(param));
      try
      {
          CommonResponse response = client.getCommonResponse(request);
          System.out.println(response.getData());
      } catch(ServerException e)
      {
          e.printStackTrace();
      } catch(ClientException e)
      {
          e.printStackTrace();
      }
    }
    public static void main(String[] args){
        AliyunSmsUtils smsUtils = new AliyunSmsUtils();
        Map map = new HashMap();
        map.put("code","captcahr");
        smsUtils.sendSms("18601034717","SMS_176995307",map);
    }


}

